import router from './router'
import store from './store'
import Cookies from 'js-cookie'
// import nprogress from 'nprogress'

// router.beforeEach((to, from, next) => {
//   // nprogress.start()
//   if(Cookies.get(TokenKey)){
//     console.log(111);
//     if(to.path=='/login'){
//       next('/')
//     }else{
//       next()
//     }
//   }else{  
//     console.log(222);
//     next('/login')
//   }
// })
router.beforeEach((to, from, next) => {
    if (store.state.token) {   //判断是否已经登录
      next();
    } else {
      next({
        path: '/login',
        // query: {redirect: to.fullPath}   //登录成功后重定向到当前页面
      });
    }
});
router.afterEach((to, from) => {
  // nprogress.done()
})